package com.feishi.core.analytic.packing.encode;


import com.feishi.core.util.common.EncryptUtil;

import java.io.ByteArrayOutputStream;

/**
 * Created by caixq on 6/26 026.
 */
public class EncodeAesExecutor implements EncodeExecutor<EncodeAesParam> {
    @Override
    public byte[] encode(byte[] bytes, EncodeAesParam param) {
        return EncryptUtil.getByteFromFormattedText(EncryptUtil.encodeAES(bytes,param.getPassword()));
    }

    @Override
    public byte[] decode(byte[] bytes, EncodeAesParam param) {
        return EncryptUtil.decodeAES(EncryptUtil.getFormattedText(bytes),param.getPassword());
    }
    public static void main(String[] args) {
        EncodeAesParam param=new EncodeAesParam("sfdsfsdewdsf234567");



        ByteArrayOutputStream out=new ByteArrayOutputStream();

        for (int i = 0; i < 1001; i++) {
            out.write((int) (Math.random()*1000));
        }
        String data=EncryptUtil.getFormattedText(out.toByteArray());


        data=data.substring(0,315);

        EncodeAesExecutor executor=new EncodeAesExecutor();
        byte[] bytes=executor.encode(data.getBytes(),param);
        System.out.println(data);
        System.out.println(bytes.length);
        System.out.println(data.length());
        System.out.println(data.getBytes().length);
        System.out.println(new String(executor.decode(executor.encode(data.getBytes(),param),param)));
    }
}
